import { findAllByPagingAll, findAllByPaging, findTotal, add, approval, removeById, expenseUpdateInfo ,batchDeleteById ,findAllByLike } from '@/api/expense'

const state = {
  expenses: []
};

const mutations = {
  SET_ACTIVITIES: (state, expenses) => {
    state.expenses = expenses
  }
};
const actions = {
  findAllByPagingAll({commit}, params) {
    return new Promise((resolve, reject) => {
      findAllByPagingAll(params).then(response => {
        commit('SET_ACTIVITIES', response.data);
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
	
	findAllByPaging({commit}, params) {
	  return new Promise((resolve, reject) => {
	    findAllByPaging(params).then(response => {
	      commit('SET_ACTIVITIES', response.data);
	      resolve(response)
	    }).catch(error => {
	      reject(error)
	    })
	  })
	},
  
  findTotal({commit}) {
    return new Promise((resolve, reject) => {
      findTotal().then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  
  add({commit}, data) {
    return new Promise((resolve, reject) => {
      add(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
	
	approval({commit}, data) {
	  return new Promise((resolve, reject) => {
	    approval(data).then(response => {
	      resolve(response)
	    }).catch(error => {
	      reject(error)
	    })
	  })
	},
	
	removeById({commit}, id) {
	  return new Promise((resolve, reject) => {
	    removeById(id).then(response => {
	      resolve(response)
	    }).catch(error => {
	      reject(error)
	    })
	  })
	},
	
	expenseUpdateInfo({commit,state},data){
	  return new Promise(((resolve, reject) =>{
	    expenseUpdateInfo(data).then((res) => {
	      resolve(res)
	    }).catch((error)=> {
	      reject(error)
	    })
	  }))
	},
	
	batchDeleteById({commit, state},ids){
	  return new Promise(((resolve, reject) => {
	    batchDeleteById(ids).then((res)=> {
	      resolve(res)
	    }).catch((error) => {
	      reject(error)
	    })
	  }))
	},
	
	findAllByLike({commit, state},string){
	  return new Promise(((resolve, reject) => {
	    findAllByLike(string).then((res)=> {
	      resolve(res)
	    }).catch((error) => {
	      reject(error)
	    })
	  }))
	},
	
 };
  
 export default {
   namespaced: true,
   state,
   mutations,
   actions
 }